package pivotIndex;

import java.util.Arrays;

public class Solution {
    public int pivotIndex(int[] nums) {
        // 前缀和
        int total = Arrays.stream(nums).sum();
        int cur = 0;
        for (int i = 0; i < nums.length; i++) {
            // (total-nums[i])/2 == cur
            // ---> cur*2 + nums[i] == total
            if(cur*2 + nums[i] == total) {
                return i;
            }
            cur+=nums[i];
        }
        return -1;
    }
}
